package com.kiwi.cases.login;

import com.kiwi.action.LoginAction;
import com.kiwi.constant.Constant;
import com.kiwi.constant.ConstantURL;
import com.kiwi.util.EncryptSet.Impl.SignatureServiceImpl;
import com.kiwi.util.EncryptSet.Interface.SignatureService;
import com.netease.shockwave.http.HttpHandler;
import com.netease.shockwave.testng.ShockwaveTestNG;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.kiwi.util.MD5Util;

/**
 * 测试接口：密码登录接口 http://uc.s.kiwi.com/api/login
 *
 * @param username
 * @param password
 * @author bjwangzheng3
 */
public class LoginWithPassword extends ShockwaveTestNG
{
    private  Logger logger = Logger.getLogger(LoginWithPassword.class);

    @BeforeClass
    public void BeforeClassTest()
    {
        logger.info("客户端：密码登录开始");

     }

    @Test(description = "客户端密码登录接口测试", dataProvider = "LoginData")
    public void test(String mobile,String password,String verifyCode,String source,String uniqueID) throws Exception {
    	String password_jiami=MD5Util.getMD5(password);
    	logger.info(password_jiami);
    	String param = String.format("mobile=%s&password=%s&verifyCode=%s&source=%s&uniqueID=%s", mobile,
    			password_jiami,verifyCode,source,uniqueID);
    	SignatureServiceImpl signatureService = new SignatureServiceImpl();
    	String params = signatureService.encodeStr(param);
    	logger.info("jiami  "+params);
    	HashMap<String, String> params_login = new HashMap<String, String>();
    	params_login.put("id", Constant.id);
    	params_login.put("deviceId", Constant.deviceId);
    	params_login.put("params", params);
    	HttpHandler handler = HttpHandler.getInstance();
        String enResult = handler.usingPostMethod(ConstantURL.LOGINURL, params_login, null);
        logger.info(enResult);
        
    }


    @DataProvider(name = "LoginData")
    public static Object[][] data(){
        return new Object[][]{
                            { "17801001938","123456a","","3","53f65bcd85e203f99ae450b41fb0ff6e"}, };
   }

    @AfterClass
    public void AfterClassTest()
    {

            logger.info("客户端：密码登录测试结束");
   }


}
